<?php
     
     header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
     header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
     header ("Cache-Control: no-cache, must-revalidate");
     header ("Pragma: no-cache");
     
     header("content-type: application/x-javascript; charset=tis-620");
    include_once('connection/connection.php');
     $data=$_GET['data'];
     $val=$_GET['val'];
	 $val1=$_GET['val1'];
	 if($data=='district')
	 {
          echo "<select name='district' id='district' class='txt' onChange=\"changeBlock('block',this.value)\" onBlur=\"changeTehsil('tehsil',this.value)\" disabled>\n";
          echo "<option value='0'>==== District ====</option>\n";
          $result=mysql_query("select DISTINCT district_id, district_name from tbl_lookup_location order by district_name");
          while(list($id, $name)=mysql_fetch_array($result))
		  {
              ?>
			   <option value="<?php echo $id; ?>" <?php if($val==$id) {echo "selected"; } ?>><?php echo $name; ?></option><?php
          }  
		  
	 }
	  
	 if($data=='block')
	 {		
         	echo "<select name='block' class='txt' onChange=\"changeTehsil('panchayat',this.value)\" disabled>\n";
         	echo "<option value='0'>=====Block====</option>\n";
         	$val2=$val;
         	$val = substr($val,0,10);                            
         	$result=mysql_query("SELECT DISTINCT block_id, block_name from tbl_lookup_location where district_id='$val' order by block_name");
         	while(list($id, $name)=mysql_fetch_array($result))
		 	{       
             	 ?>
             	 <option value="<?php echo $id; ?>" <?php if($val1==$id) {echo "selected"; } ?>><?php echo $name; ?></option> 
			<?php
         	}	 	
		}
		
		if($data=='tehsil')
		 {
		 	echo "<select name='tehsil' class='txt' disabled>\n
         	<option value='0'>=====Tehsil====</option>\n";
		 	$result1=mysql_query("SELECT DISTINCT census_subdistrict_code,census_subdistrict_name from tbl_lookup_location where district_id='$val' order by census_subdistrict_name");
		 	while(list($id1, $name1)=mysql_fetch_array($result1))
		 	{       
              	?>
             	 <option value="<?php echo $id1; ?>" <?php if($val1==$id1) {echo "selected"; } ?>><?php echo $name1; ?></option> 
			<?php
         	}	 	
	}
	 else if ($data=='panchayat') 
	 {
		 $val2=$val;
		 $val = substr($val,0,10);
          echo "<select name='panchayat' class='txt' onChange=\"changePanchayat('village',this.value)\" disabled>\n";
          echo "<option value='0'>=Gram panchayat=</option>\n";
          $val2=$val;
		  $val = substr($val,0,10);
          $result=mysql_query("SELECT DISTINCT panchayat_id, panchayat_name from tbl_lookup_location where block_id='$val' order by panchayat_name");
          while(list($id, $name)=mysql_fetch_array($result))
		  {
               ?>
             	 <option value="<?php echo $id; ?>" <?php if($val1==$id) {echo "selected"; } ?>><?php echo $name; ?></option> 
			<?php
          }
	  }  
	 else if ($data=='village') 
	  {
		 $val2=$val;
		 $val = substr($val,0,10);
		  //echo "Value2:".$val2;
		  //echo "Value:".$val;
          echo "<select  name='village' class='txt' onChange=\"changeVillage('habit',this.value);changeCensusCode('cvc',this.value);changeFormId(this.form,'form_id',this.value)\" >\n";
          echo "<option value='0'>=====Village====</option>\n";
          $val2=$val;
		  $val = substr($val,0,10);
          $result=mysql_query("SELECT DISTINCT village_id, village_name from tbl_lookup_location where panchayat_id='$val' order by village_name");
          while(list($id, $name)=mysql_fetch_array($result))
		  {
               ?>
             	 <option value="<?php echo $id; ?>" <?php if($val1==$id) {echo "selected"; } ?>><?php echo $name; ?></option>
             	 <?php
          }
		}
		
		else if ($data =='cvc') 
	  	{
			$val2=$val;
			$val = substr($val,0,10);
		    //echo "Value2:".$val2;
		    //echo "Value:".$val;
		   $result=mysql_query("SELECT DISTINCT census_village_code from tbl_lookup_location where village_id='$val' order by village_name");
         while(list($id1)=mysql_fetch_array($result))
		 { ?>
             	 <input type="text" name="cvc" value="<?php echo $id1;?>" readonly class=txt size=20 style="color:#FF0000">
			  
         <?php }
		 }
		
		else if ($data =='form_id') 
	  	{
		 	$val2=$val;
			$val = substr($val,0,10);
			$dist=$_GET['dist'];
	 	 	//echo $dist;
			$qid="UPDATE sequence SET id=LAST_INSERT_ID(id+1)";
			$rid = mysql_query($qid);
			$qryId="select id from sequence";
			//echo $qryId;
			$recId=mysql_query($qryId);
			$rowId=mysql_fetch_array($recId);
			$id=$rowId['id'];
		   	//$qid = "SELECT MAX(id) AS id FROM tbl_dtls_q2_main";
			//$z = mysql_fetch_array($rid);
			//$id = $z['id'];
			//if(mysql_num_rows($rid)<0)
			//{
			//	$id = 1;
			//}
			//else
			//{
			//	$id++;
			//}
			
			$form_id = substr($dist,0,4);
			$form_id = "Q2" . "-" . $form_id . "-"  . $id;
			//$form_id = "000" . $id;  ?>
			<input type="text" style="color:#FF0000" name="form_id" value="<?php echo $form_id; ?>" readonly class=txt size=20>
			<input type="hidden" style="color:#FF0000" name="id" value="<?php echo $id; ?>" readonly class=txt size=20>
		<?php } 
	 else if ($data=='habit') 
	  {
		 $val2=$val;
		 $val = substr($val,0,10);
		  //echo "Value2:".$val2;
		  //echo "Value:".$val;
		   //$q="SELECT DISTINCT habitation_code, CONCAT(UPPER(LEFT(`habitation_name`, 1)), LOWER(SUBSTRING(`habitation_name`,2))) from tbl_lookup_location where census_village_code='$val' order by habitation_name";
		   $q="SELECT DISTINCT habitation_code, habitation_name from tbl_lookup_location where village_id='$val' order by habitation_code";
          $val2=$val;
		  $val = substr($val,0,10);
          $result=mysql_query($q);
		  $num_habit = mysql_num_rows($result);
		   $i=1;
		   $sqlGetHabitationDetails="select * from tbl_dtls_q1_oh where loc_id=$val1 order by habit_code asc";
			$queryGetHabitationDetails=mysql_query($sqlGetHabitationDetails);
		  //while(list($id, $name)=mysql_fetch_array($result))
		  //{
		  	while($rowGetHabitationDetails=mysql_fetch_array($queryGetHabitationDetails)){
		  ?>
		  <table width="95%">
			<tr>
				<td width="22%" align="center"><font id=habit>
					<input type="text" name="name_habi<?php echo $i;?>" id="name_habi<?php echo $i;?>" value="<?php echo ucwords(strtolower($rowGetHabitationDetails['habit_name']));?>" class="txt7" readonly></font>
				</td>
				<td width="15%" align="left"><font id=habit_code>
					<input type="text" name="habi_code<?php echo $i;?>" id="habi_code<?php echo $i;?>" value="<?php echo $rowGetHabitationDetails['habit_code'];?>" class="txt7" readonly></font>
				</td>
				<td align="center" width="4%"><input type="text" name="type_habit<?php echo $i;?>" id="type_habit<?php echo $i;?>" value="<?php if($i==1){ echo "MH"; } else { echo "OH"; } ?>" size="2" class="txt_1" readonly/></td>
				<td width="18%" align="center">
					<input type="radio" name="status<?php echo $i;?>" id="status<?php echo $i;?>" value="Existing" <?php echo  ($rowGetHabitationDetails['status_e_nt']=='Existing')?'checked':'';?> onClick="setEnable(this.value,<?php echo $i; ?>)"><font style="font-size: 8.5pt" face="Verdana" color="#000000">E</font>
					<input type="radio" name="status<?php echo $i;?>" id="status<?php echo $i;?>" onClick="setReadOnly(this.value,<?php echo $i; ?>)" value="NON TRACABLE" <?php echo  ($rowGetHabitationDetails['status_e_nt']=='NON TRACAB')?'checked':'';?>><font style="font-size: 8.5pt" face="Verdana" color="#000000">NT</font></p>
				</td>
			</tr></table>
		<?php
		$i++;
          }  
		 // }
		  echo "<input type='hidden' name='habit_count' id='habit_count' value=".$num_habit."></table>"; 
    }
?>